package classesDummy;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class ProbaFiltreMes {

	public static void main(String[] args) throws Exception {

		Calendar ini = Calendar.getInstance();
		ini.set(2008, 02, 10);
		Calendar fi = Calendar.getInstance();
		fi.set(2008, 05, 22);

		filtrarMes(ini, fi);

	}

	private static void filtrarMes(Calendar dataIni, Calendar dataFi)
			throws Exception {

		Calendar dataCal = Calendar.getInstance();
		dataCal.set(2008, 04, 01);

		SimpleDateFormat df = new SimpleDateFormat();
		df.applyPattern("dd/MM/yyyy");
		System.out.println(df.format(dataCal.getTime()));

		if (dataIni.before(dataFi) && dataFi.after(dataCal)) {

			if (dataIni.get(Calendar.MONTH) != dataCal.get(Calendar.MONTH)) {
				dataIni.set(dataCal.get(Calendar.YEAR),
						dataCal.get(Calendar.MONTH), dataIni.getActualMinimum(Calendar.DATE));
			}
			else {
			dataIni.set(dataCal.get(Calendar.YEAR),
					dataCal.get(Calendar.MONTH), dataIni.get(Calendar.DATE));
				}
			
			if (dataFi.get(Calendar.MONTH) != dataCal.get(Calendar.MONTH)) {
				
				dataFi.set(dataCal.get(Calendar.YEAR),
						dataCal.get(Calendar.MONTH), dataIni.getActualMaximum(Calendar.DATE));
			}else {
			
			dataFi.set(dataCal.get(Calendar.YEAR), dataCal.get(Calendar.MONTH),
					dataFi.get(Calendar.DATE));
			}
		}

		else {
			throw new Exception("Data No VALIDA");
		}

		System.out.println(df.format(dataIni.getTime()));

		System.out.println(df.format(dataFi.getTime()));
	}

}
